package com.atguigu.config;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Author：请允悲
 * @Slogan：致敬大师
 * @Package：com.atguigu.config
 * @Project：springsecuritydemo
 * @name：SecurityConfig
 * @Date：2023/9/27 10:49
 * @Filename：SecurityConfig
 */

//@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
         BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
         String password = passwordEncoder.encode("password2");
        auth.inMemoryAuthentication().withUser("root2").password(password).roles("admin");
    }

    //注入PasswordEncoder类到spring容器中
    @Bean
    PasswordEncoder password(){
        return new BCryptPasswordEncoder();
    }


}
